package cn.cupster.flowdemo.adapter

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import cn.cupster.flowdemo.bean.Vp2PageBean
import cn.cupster.flowdemo.fragment.Vp2PageFirstFragment
import cn.cupster.flowdemo.fragment.Vp2PageFragment

/**
 * @param items 数据类型
 */
class Vp2FragmentStateAdapter(fragmentActivity: FragmentActivity , items : MutableList<Vp2PageBean?>? ): FragmentStateAdapter(fragmentActivity) {

    var readItems = items

    override fun getItemCount(): Int {
        return if (readItems == null ){
            0
        }else{
            readItems!!.size
        }
    }

    override fun createFragment(position: Int): Fragment {
        if (readItems == null || readItems!![position] == null){
            return Fragment()
        }
        if (position == 0){
            return Vp2PageFirstFragment.create(readItems!![position] )
        }
        return Vp2PageFragment.create(readItems!![position] )
    }

}